angular.module('app').controller('allCtrl', ['$scope', '$state', '$http', 'product', 'utils', 'userInfo', function($scope, $state, $http, product, utils, userInfo) {

	$scope.productList = []
	/*页面加载完成以后初始化下拉刷新*/
	$scope.$on('$viewContentLoaded', function(event) {
		var oh = document.documentElement.clientHeight
		/*设置滚动区域高度*/
		$("#pullrefresh").height((oh - 44 - 55 - 10) + 'px')
		mui("#pullrefresh").pullRefresh({
			down: {
				height: 50,
				callback: pulldownRefresh,
				auto: true
			}
		})

	});
	/*下拉刷新默认屏蔽链接跳转,只能这样解决*/
	mui('.all-list').on('tap', 'li', function() {
		$state.go($(this).attr("ev-href"), {
			productId: $(this).attr("productId")
		})
		product.productInfo = JSON.parse($(this).attr("productInfo"))
	});

	mui(document).on('tap','#goOther',function(){
		$state.go("moreProduct")
	})

	/*获取是否新手*/
	userInfo.getUserIsNew()

	/*下拉刷新方法*/
	function pulldownRefresh() {
		$http.post(utils.productSys, {}, {
			params: {
				header: utils.header("030050"),
				body: {
					userType:userInfo.is_new_user
				}
			}
		}).then(function(res) {
			if(res.header.re_code=="0000"){
				$scope.productList=res.body.productInfoList
			}
		})

		mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
	}

	/*购买*/
	mui('.all-list').on("tap", "#buy", function(e) {
		var info = JSON.parse($(this).parent().parent().attr("productinfo")) //获取产品详情
		product.productInfo = info //更新产品服务
		if($(this).attr("kegou") != 0) {
			e.stopPropagation()
			userInfo.buy(info)
		}

	})
	
}])